<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>jxs使用</title>
</head>

<body>
  <div id="root">

  </div>
  <div id="root1"></div>
  <div id="root2"></div>
  <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.js"></script>
  <script type="text/babel">
    // 使用表达式
    const name = 'Josh Perez';
    const element = <h1>Hello, {name}</h1>;
    console.log(element)
    ReactDOM.render(
      element,
      document.getElementById('root')
    );
  </script>
  <script type="text/babel">
    //jsx 中 函数调用
    function formatName(user) {
      return user.firstName + ' ' + user.lastName;
    }
    const user = {
      firstName: 'Harper',
      lastName: 'Perez'
    };
    const element = (
      <h1>
        Hello, {formatName(user)}!
  </h1>
    );
    ReactDOM.render(element, document.getElementById('root1'))
  </script>
  <script type="text/babel">
    // jsx 也可以是表达式
    function getGreeting(user) {
      if (user) {
        return <h1>Hello, {formatName(user)}!</h1>;
      }
      return <h1>Hello, Stranger.</h1>;
    }
    ReactDOM.render(getGreeting(),document.getElementById('root2'))
  </script>
</body>

</html>